/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Home-pc
 * Date: 2023-09-23
 * Time: 11:33
 */
//单例模式（饿汉模式）
    class Singleton{
        private static Singleton instance=new Singleton();

    public static Singleton getInstance() {
        return instance;
    }
    //做一个限制，禁止别人去new这个实例
    private Singleton(){

    }
}
public class Demo15 {
    public static void main(String[] args) {
        Singleton s1=Singleton.getInstance();
        Singleton s2=Singleton.getInstance();

        System.out.println(s1==s2);

        //Singleton s3=new Singleton();

        //System.out.println(s1==s3);
    }
}
